home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / pdevtest / pdevtest.c.save < prev    next >
Encoding:
Text File  |  1989-10-06  |  7.2 KB  |  274 lines

  1. /*
  2.  * Test driver for the pseudo-device implementation.
  3.  *
  4.  * The programs output goes to standard out, while the
  5.  * statistics taken go to error output or another file.
  6.  */
  7.  
  8. #include <sprite.h>
  9. #include <status.h>
  10. #include <stdio.h>
  11. #include <fs.h>
  12. #include <fsCmd.h>
  13. #include <sysStats.h>
  14. #include <rpc.h>
  15. #include <proc.h>
  16. #include <vm.h>
  17. #include <kernel/sched.h>
  18. #include <kernel/fsStat.h>
  19. #include <kernel/vm.h>
  20. #include <option.h>
  21. #include "pdevInt.h"
  22.  
  23. Boolean clean = FALSE;
  24. Boolean histogram = FALSE;
  25. Boolean useSelect = FALSE;
  26. Boolean copy = FALSE;
  27. Boolean readP = FALSE;
  28. Boolean writeP = FALSE;
  29. Boolean ioctlP = FALSE;
  30. Boolean selectP = FALSE;
  31. Boolean switchBuf = FALSE;
  32. Boolean writeBehind = FALSE;
  33. int size = 128;
  34. int reps = 100;
  35. int numClients = -1;            /* For multi-program synchronization,
  36.                      * this is the number of slaves with
  37.                      * which to synchronize */
  38. int delay = 0;                /* Delay loop for server to eat CPU */
  39. Boolean slave = FALSE;
  40. char outFileDefault[] = "pdevtest.out";
  41. char *outFile = outFileDefault;
  42.  
  43. Option optionArray[] = {
  44.     {OPT_INT, "M", (Address)&numClients,
  45.         "Master for -M (int) clients"},
  46.     {OPT_TRUE, "S", (Address)&slave,
  47.         "Slave bench program\nTests:"},
  48.     {OPT_STRING, "o", (Address)&outFile,
  49.         "Output file name"},
  50.     {OPT_STRING, "p", (Address)&pdev,
  51.         "Name of the master pseudo device"},
  52.     {OPT_TRUE, "i", (Address)&ioctlP,
  53.         "IOControl test"},
  54.     {OPT_TRUE, "r", (Address)&readP,
  55.         "Read test"},
  56.     {OPT_TRUE, "w", (Address)&writeP,
  57.         "Write test"},
  58.     {OPT_TRUE, "W", (Address)&writeBehind,
  59.         "Enable write behind (with -M)"},
  60.     {OPT_TRUE, "s", (Address)&selectP,
  61.         "Select, makes master block client"},
  62.     {OPT_TRUE, "c", (Address)©,
  63.         "Copy stream test, the slave forks"},
  64.     {OPT_INT, "n", (Address)&reps,
  65.         "Number of repetitions"},
  66.     {OPT_INT, "d", (Address)&size,
  67.         "Amount of data to transfer"},
  68.     {OPT_INT, "P", (Address)&delay,
  69.         "Loop for -P <int> cylces before replying"},
  70.     {OPT_TRUE, "z", (Address)&useSelect,
  71.         "Force Master to use select with 1 client"},
  72.     {OPT_TRUE, "b", (Address)&switchBuf,
  73.         "Test switching request buffers (use with -i)\nTracing:"},
  74.     {OPT_TRUE, "x", (Address)&clean,
  75.         "Turn off all tracing"},
  76.     {OPT_TRUE, "h", (Address)&histogram,
  77.         "Leave histograms on (ok with -x)"},
  78. };
  79. int numOptions = sizeof(optionArray) / sizeof(Option);
  80.  
  81. FsStats fsStartStats, fsEndStats;
  82. Vm_Stat    vmStartStats, vmEndStats;
  83. Time startTime, endTime;
  84. Sched_Instrument startSchedStats, endSchedStats;
  85.  
  86. main(argc, argv)
  87.     int argc;
  88.     char *argv[];
  89. {
  90.     register ReturnStatus status = SUCCESS;
  91.     Proc_PID child;
  92.     Proc_ResUsage usage;
  93.     FILE * outStream;
  94.     register int i;
  95.     ClientData serverData, clientData;
  96.  
  97.     argc = Opt_Parse(argc, argv, optionArray, numOptions, OPT_ALLOW_CLUSTERING);
  98.     if (!slave && (numClients < 0)) {
  99.     fprintf(stderr, "Master: %s [-xfpoh] -M numSlaves\n",
  100.                 argv[0]);
  101.     fprintf(stderr, "Slave: %s [-xfpoh] -S\n", argv[0]);
  102.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  103.     exit(1);
  104.     }
  105.     if (size > MAX_SIZE) {
  106.     size = MAX_SIZE;
  107.     }
  108.     if (clean) {
  109.     int newValue;
  110.     newValue = 0;
  111.     Fs_Command(FS_SET_CACHE_DEBUG, sizeof(int), &newValue);
  112.     newValue = 0;
  113.     Fs_Command(FS_SET_TRACING, sizeof(int), &newValue);
  114.     newValue = 0;
  115.     Fs_Command(FS_SET_RPC_DEBUG, sizeof(int), &newValue);
  116.     newValue = 0;
  117.     Fs_Command(FS_SET_RPC_TRACING, sizeof(int), &newValue);
  118.     if (!histogram) {
  119.         newValue = 0;
  120.         (void) Fs_Command(FS_SET_RPC_SERVER_HIST, sizeof(int), &newValue);
  121.         newValue = 0;
  122.         (void) Fs_Command(FS_SET_RPC_CLIENT_HIST, sizeof(int), &newValue);
  123.     }
  124.     }
  125.     outStream = fopen(outFile, "w+");
  126.     if (outStream == (FILE *)NULL) {
  127.     perror(outFile);
  128.     exit(status);
  129.     }
  130.     /*
  131.      * Copy command line to output file.
  132.      */
  133.     fprintf(outStream, "%s ", argv[0]);
  134.     if (clean) {
  135.     fprintf(outStream, "-x ");
  136.     }
  137.     if (histogram) {
  138.     fprintf(outStream, "-h ");
  139.     }
  140.     if (clean) {
  141.     fprintf(outStream, "-x ");
  142.     }
  143.     for (i=1 ; i<argc ; i++) {
  144.     fprintf(outStream, "%s ", argv[i]);
  145.     }
  146.     fprintf(outStream, "\n");
  147.     /*
  148.      * Check for multi-program master/slave setup.
  149.      */
  150.     if (numClients > 0) {
  151.     ServerSetup(numClients, &serverData);
  152.     slave = FALSE;
  153.     }
  154.     if (slave) {
  155.     ClientSetup(&clientData);
  156.     }
  157.     /*
  158.      * Get first sample of filesystem stats, vm stats, time, and idle ticks.
  159.      */
  160.     status = Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsStartStats);
  161.     if (status != SUCCESS) {
  162.     Stat_PrintMsg(status, "Error getting FS stats");
  163.     exit(status);
  164.     }
  165.     status = Vm_Cmd(VM_GET_STATS, &vmStartStats);
  166.     if (status != SUCCESS) {
  167.     Stat_PrintMsg(status, "Error getting VM stats");
  168.     exit(status);
  169.     }
  170.     status = Sys_Stats(SYS_SCHED_STATS, 0, &startSchedStats);
  171.     if (status != SUCCESS) {
  172.     Stat_PrintMsg(status, "Error in Sys_Stats");
  173.     exit(status);
  174.     }
  175.  
  176.     status = Sys_GetTimeOfDay(&startTime, NULL, NULL);
  177.     if (status != SUCCESS) {
  178.     Stat_PrintMsg(status, "Error in Sys_GetTimeOfDay");
  179.     exit(status);
  180.     }
  181.     if (slave) {
  182.     if (copy) {
  183.         child = fork();
  184.     }
  185.     if (readP) {
  186.         ClientRead(clientData, size, reps);
  187.     }
  188.     if (writeP) {
  189.         ClientWrite(clientData, size, reps);
  190.     }
  191.     if (ioctlP) {
  192.         ClientIOControl(clientData, size, reps);
  193.     }
  194.     if (copy) {
  195.         if (child != 0) {
  196.         (void)wait(0);
  197.         } else {
  198.         exit(0);
  199.         }
  200.     }
  201.     /*
  202.      * Take ending statistics and print user, system, and elapsed times.
  203.      */
  204.     Sys_GetTimeOfDay(&endTime, NULL, NULL);
  205.     Sys_Stats(SYS_SCHED_STATS, 0, &endSchedStats);
  206.     Time_Subtract(endTime, startTime, &endTime);
  207.     printf("Slave: ");
  208.     PrintTimes(stdout, &usage, &endTime);
  209.  
  210.     Sys_Shutdown(0);    /* sync cache */
  211.     ClientDone(clientData);
  212.  
  213.     Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsEndStats);
  214.     Vm_Cmd(VM_GET_STATS, &vmEndStats);
  215.     /*
  216.      * Print FS statistics.
  217.      */
  218.     fprintf(outStream, "C: ");
  219.     PrintIdleTime(outStream, &startSchedStats, &endSchedStats, &endTime);
  220.     PrintFsStats(outStream, &fsStartStats, &fsEndStats);
  221.     /*
  222.      * Print VM statistics.
  223.      */
  224.     PrintVmStats(outStream, &vmStartStats, &vmEndStats);
  225.     } else {
  226.     /*
  227.      * Drop into the top level service loop.  ServeOne is a faster
  228.      * version that doesn't use select because there is only
  229.      * one client.
  230.      */
  231.     if (numClients > 1 || useSelect) {
  232.         Serve(serverData);
  233.     } else {
  234.         ServeOne(serverData);
  235.     }
  236.     /*
  237.      * Take ending statistics and print user, system, and elapsed times.
  238.      */
  239.     Sys_GetTimeOfDay(&endTime, NULL, NULL);
  240.     Sys_Stats(SYS_SCHED_STATS, 0, &endSchedStats);
  241.     Time_Subtract(endTime, startTime, &endTime);
  242.     printf("Master: ");
  243.     PrintTimes(stdout, &usage, &endTime);
  244.  
  245.     Sys_Shutdown(0);    /* sync cache */
  246.     Fs_Command(FS_RETURN_STATS, sizeof(FsStats), &fsEndStats);
  247.     Vm_Cmd(VM_GET_STATS, &vmEndStats);
  248.     /*
  249.      * Print FS statistics.
  250.      */
  251.     fprintf(outStream, "S: ");
  252.     PrintIdleTime(outStream, &startSchedStats, &endSchedStats, &endTime);
  253.     PrintFsStats(outStream, &fsStartStats, &fsEndStats);
  254.     /*
  255.      * Print VM statitistics.
  256.      */
  257.     PrintVmStats(outStream, &vmStartStats, &vmEndStats);
  258.  
  259.     if (delay > 0) {
  260.         int cnt;
  261.         Sys_GetTimeOfDay(&startTime, NULL, NULL);
  262.         for (cnt=0 ; cnt<50 ; cnt++) {
  263.         for (i=delay<<1 ; i>0 ; i--) ;
  264.         }
  265.         Sys_GetTimeOfDay(&endTime, NULL, NULL);
  266.         Time_Subtract(endTime, startTime, &endTime);
  267.         Time_Divide(endTime, 50, &endTime);
  268.         printf("%d.%06d seconds service delay\n",
  269.         endTime.seconds, endTime.microseconds);
  270.     }
  271.     }
  272.     exit(status);
  273. }
  274.